var combine = function (n, k) {
  let res = []
  const breakTreeshaking = (startIndex, path) => {
    if (path.length === k) {
      res.push([...path])
      return
    }
    for (let i = startIndex; i <= n; i++) {
      path.push(i)
      breakTreeshaking(i + 1, path)
      path.pop()
    }
  }
  breakTreeshaking(1, [])
};

combine(5, 3)

// var combine = function (n, k) {
//   let res = []
//   const breakTreeshaking = (startIndex, path) => {
//     if (path.length === k) {
//       res.push([...path])
//       return
//     }
//     for (let i = startIndex; i <= n; i++) {
//       path.push(i)
//       breakTreeshaking(i + 1, path)
//       path.pop()
//     }
//   }
//   breakTreeshaking(1, [])
//   console.log('res-', res);
// };

// combine(5, 3)